import {Message} from 'element-ui'

/**
 * @author liubaohui
 * @desc 检查派工规则时否满足数字倒序
 */
export default function checkAssignRule(list) {
  let assignRuleArr = []
  list.map(value => {
    if (value.assignRule !== undefined) {
      if (value.assignRule.includes('-')) {
        assignRuleArr.push(Number(value.assignRule.split('-')[1]))
      } else {
        assignRuleArr.push(0)
      }
    }
  })
  if (list.length !== assignRuleArr.length) {
    Message.error({
      message: '请先填写完成派工规则',
      duration: 1500,
      center: true
    })
    return false
  }
  if (JSON.parse(JSON.stringify(assignRuleArr)).toString() !== assignRuleArr.sort((a, b) => b - a).toString()) {
    Message.error({
      message: '派工规则不满足按工艺顺序从大到小条件',
      duration: 1500,
      center: true
    })
    return false
  }
  return true
}
